package com.vmove.childtrain.fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.vmove.childtrain.R;
import com.vmove.childtrain.adapter.UserAdapter;
import com.vmove.childtrain.common.BaseFragment;
import com.vmove.childtrain.common.quickadapter.BaseAdapterHelper;
import com.vmove.childtrain.common.quickadapter.QuickAdapter;
import com.vmove.childtrain.db.dao.UserDao;
import com.vmove.childtrain.db.entity.User;
import com.vmove.childtrain.view.RecycleViewDivider;

import java.sql.SQLException;
import java.util.List;

import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;
import butterknife.OnClick;

public class SecondFragment extends BaseFragment {


    @BindView(R.id.recycler)
    RecyclerView recycler;
    @BindView(R.id.iv_userSelect)
    ImageView ivUserSelect;
    @BindView(R.id.iv_userAdd)
    ImageView ivUserAdd;

    private List<User> users;
    private UserDao userDao;
    private UserAdapter userAdapter;

    @Override
    protected View loadView(LayoutInflater inflater) {
        return inflater.inflate(R.layout.fragment_second, null);
    }

    @Override
    protected void bindView(View rootView) {
        userDao = new UserDao(mContext);
        try {
            users= userDao.getAll();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        GridLayoutManager gridLayoutManager = new GridLayoutManager(mContext, 3);
        RecycleViewDivider dividerH = new RecycleViewDivider(mContext, LinearLayout.HORIZONTAL,12,
                getResources().getColor(R.color.white));
        RecycleViewDivider dividerV = new RecycleViewDivider(mContext, LinearLayout.VERTICAL,5,
                getResources().getColor(R.color.white));
        recycler.addItemDecoration(dividerH);
        recycler.addItemDecoration(dividerV);
        recycler.setLayoutManager(gridLayoutManager);
        userAdapter = new UserAdapter(mContext, users);
        recycler.setAdapter(userAdapter);
    }

    @OnClick({R.id.iv_userSelect, R.id.iv_userAdd})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_userSelect:
                break;
            case R.id.iv_userAdd:
                break;
        }
    }
}
